/**
 * 
 */
package tech.abing.spider.task.pageprocessor.amac;

import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import tech.abing.spider.component.PageProcessor;
import tech.abing.spider.component.PageScript;
import tech.abing.spider.model.Proccessable;
import tech.abing.spider.page.OkPage;
import tech.abing.spider.page.Page;
import tech.abing.spider.request.BasicRequest;
import tech.abing.spider.request.PageRequest;
import tech.abing.spider.request.StartContext;
import tech.abing.spider.task.model.amac.AssetSupportSpecialDetailEntity;
import tech.abing.spider.util.UuIdPublic;

/**
 * 类说明
 * @author HUNING
 * @since 2018-1-8
 * 
 */
public class AssetSupportSpecialDetailProcessor implements PageProcessor{
private static Logger logger = Logger.getLogger(AssetSupportSpecialDetailProcessor.class);
	
	@Override
	public PageScript getJavaScript() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Pattern getNormalContain() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void process(OkPage page, StartContext context,
			List<BasicRequest> queue, List<Proccessable> objectContainer)
			throws Exception {
		Document doc = Jsoup.parse(page.getContent());
		PageRequest request = page.getRequest();
		Element table = doc.select("body > div:nth-child(3) > div.contentleft2 > table:nth-child(1) > tbody").first();
		
		AssetSupportSpecialDetailEntity detail = new AssetSupportSpecialDetailEntity();
		detail.setId(UuIdPublic.timeStrongID(5));
		detail.setAspiName(table.select(" tr:nth-child(1) > td:nth-child(2)").text());
		detail.setAspiSortName(table.select("  tr:nth-child(2) > td:nth-child(2)").text());
		detail.setHoldDate(table.select("  tr:nth-child(3) > td:nth-child(1)").text());
		detail.setPublishPlace(table.select(" tr:nth-child(3) > td:nth-child(2)").text());
		detail.setTransferPlace(table.select(" tr:nth-child(4) > td:nth-child(1)").text());
		detail.setSetupDate(table.select(" tr:nth-child(4) > td:nth-child(2)").text());
		detail.setRightsPerson(table.select(" tr:nth-child(5) > td:nth-child(1)").text());
		detail.setManagerName(table.select(" tr:nth-child(5) > td:nth-child(2)").text());
		
		table = doc.select("body > div:nth-child(3) > div.contentleft2 > table:nth-child(3) > tbody").first();
		detail.setCustodian(table.select("  tr:nth-child(1) > td:nth-child(3)").text());
		detail.setServiceOrg(table.select(" tr:nth-child(2) > td:nth-child(2)").text());
		detail.setSuperviseOrg(table.select(" tr:nth-child(3) > td:nth-child(2)").text());
		detail.setSalesOrg(table.select(" tr:nth-child(4) > td:nth-child(2)").text());
		detail.setRateOrg(table.select("  tr:nth-child(5) > td:nth-child(2)").text());
		detail.setEstimateOrg(table.select(" tr:nth-child(6) > td:nth-child(2)").text());
		detail.setAccountingFirm(table.select(" tr:nth-child(7) > td:nth-child(2)").text());
		detail.setLawFirm(table.select(" tr:nth-child(8) > td:nth-child(2)").text());
		detail.setRegistOfSecurOrg(table.select(" tr:nth-child(9) > td:nth-child(2)").text());
		detail.setOtherOrg(table.select(" tr:nth-child(10) > td:nth-child(2)").text());
		detail.setUrl(request.getUrl());
		detail.setCreateTime(new Date());
		objectContainer.add(detail);
	}

	@Override
	public void processErrorPage(Page page, StartContext context,
			List<Proccessable> objectContainer) throws Exception {
		
	}

}
